package project.euler.honk.problem.to50;

public final class Problem33 {

	private static boolean check(int a, int b) {
		if ((a % 10) == (b / 10))
			return a * (b % 10) == b * (a / 10);
		else
			return false;
	}

	public static int solve() {
		int x = 1;
		int y = 1;
		for (int a = 10; a < 100; a++) {
			for (int b = a + 1; b < 100; b++) {
				if (a % 5 == 0 && b % 5 == 0)
					continue;
				if (check(a, b) && b != 96) {
					x *= a;
					y *= b;
				}
			}
		}
		for (int i = 2; i <= x; i++) {
			if (x % i == 0 && y % i == 0) {
				x /= i;
				y /= i;
				i = 2;
			}
		}
		return y;
	}
	
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		long result = solve();
		long end = System.currentTimeMillis();
		System.out.println("Result: " + result + " Time: " + (end - start));
	}
}
